//本项目为格斗游戏的设计

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <Windows.h>
#include <conio.h>
#include <time.h>
#include <math.h>
#include "battle.h"


//输入转换器
void ChangeInput(int* choose,int* move,int* skill)
{
	int input = 0;
	
	printf("移动(a:后退 d:前进 其他:跳过)\n");
	input = _getch();
	switch (input)
	{
		case 'a':
			*move = 2; break;
		case 'd':
			*move = 1; break;
		default:
			*move = 0; break;
	}
	printf("选择攻击(j:轻攻击 k:中攻击 i:重攻击 h:防御 其他:跳过)\n");
	input = _getch();
	switch (input)
	{
	case 'j':
		*choose = 1; break;
	case 'k':
		*choose = 2; break;
	case 'i':
		*choose = 3; break;
	case 'h':
		*choose = 4; break;
	default:
		*choose = 0; break;
	}
	printf("选择技能(u+其他:十星炮 u+d:升龙斩 u+o:十天极 其他:跳过)\n");
	input = _getch();
	switch (input)
	{
		case 'u':
			input = _getch();
			switch (input)
			{
				case 'd':
					*skill = 2;
				case 'o':
					*skill = 3;
				default:
					*skill = 1; break;
			}
		default:
			*skill = 0; break;
	}
}

int main()
{
	//随机种子
	srand((unsigned)time(NULL));
	int choose1 = 0;
	int choose2 = 0;
	int move1 = 0;
	int move2 = 0;
	int skill1 = 0;
	int skill2 = 0;
	int action1 = 0;
	int action2 = 0;
	int player_len = 0;
	int log_out = 0;
	herolist listdata;
	herodata hero1;
	herodata hero2;
	//人物初始化(初始人物)
	InitHero(&listdata.list[0], "古兰", 100, 20, 10, 2,0);
	InitHero(&listdata.list[1], "姬塔", 100, 30, 5, 4,1);
	listdata.heronum = 2;
	while (1)
	{
		//用户主菜单
		log_out=Menu(&listdata,&hero1,&hero2);
		//用户退出检定
		if (log_out==1)
		{
			printf("goodbye!\n");
			return 0;
		}
		printf("Battle Start!\n");
		//战斗开始
		while (hero1.HP > 0 && hero2.HP > 0)
		{
			printf("\n");
			//英雄状态打印
			Print_Hero_Data(hero1, hero2);
			Sleep(500);
			//动作计数器
			action1 = 0;
			action2 = 0;
			//硬直计数器
			Init_Hero_Stun(&hero1);
			Init_Hero_Stun(&hero2);
			//随机操作
//			choose1 = rand() % 4 + 1;
			choose2 = rand() % 4 + 1;
//			move1 = rand() % 2 + 1;
			move2 = rand() % 2 + 1;
//			skill1 = rand() % 4 + 1;
			skill2 = rand() % 4 + 1;
			//输入转换器
			ChangeInput(&choose1,&move1,&skill1);
			//硬直检定
			Stun_Check(hero1);
			Stun_Check(hero2);
			printf("\n");
			Sleep(500);
			//移动检定
			Move_Check(&hero1, &hero2, &move1, &move2, player_len);
			Sleep(500);
			//玩家移动后距离检定
			player_len = Player_Len_Check(hero1, hero2);
			//追击检定
			Add_Attack(hero1, &choose2);
			Add_Attack(hero2, &choose1);
			//防御检定
			Def_Check(choose1, hero1);
			Sleep(500);
			Def_Check(choose2, hero2);
			Sleep(500);
			//技能检定
			action1 = Skill_Check(&hero1, &hero2, skill1, skill2, choose1, choose2, player_len);
			Sleep(500);
			action2 = Skill_Check(&hero2, &hero1, skill2, skill1, choose2, choose1, player_len);
			Sleep(500);
			//能否继续攻击检定
			Continue_Attack(&choose1, action1);
			Continue_Attack(&choose2, action2);
			//基本攻击检定
			if (player_len <= 2)
			{
				//相杀检定
				if (choose1 == choose2 && choose1 != 4 && hero1.Stun == 0 && hero2.Stun == 0 && action1 == 0 && action2 == 0)
				{
					printf("相杀,不造成伤害!\n");
					continue;
				}
				//攻击检定
				hero2 = Attack_Check(choose1, choose2, hero1, hero2, action1);
				Sleep(500);
				hero1 = Attack_Check(choose2, choose1, hero2, hero1, action2);
				Sleep(500);
			}
			Sleep(500);
			printf("\n");
		}
		Victory_Check(&hero1, &hero2,&listdata);
	}

	return 0;
}